from google.appengine.ext import db

class Transaction(db.Model):
    ctime = db.DateTimeProperty(auto_now_add=False)
    mtime = db.DateTimeProperty(auto_now_add=False)
    status = db.StringProperty()
    description = db.StringProperty()
    owner = db.UserProperty()
    
class SqlRequest(db.Model):
    transaction_ref = db.ReferenceProperty(Transaction)
    ctime = db.DateTimeProperty(auto_now_add=False)
    mtime = db.DateTimeProperty(auto_now_add=False)
    status = db.StringProperty()
    sql = db.StringProperty()
    description = db.StringProperty()
    owner = db.UserProperty()
    
    

def add_transaction(transcation, sqls):
    t = Transaction()
    t.status = transaction['status']
    t.description = transaction['description']
    t.owner = transaction['owner']
    t.put()
    for sql in sqls:
        add_sql(t, sql)


def add_sql(t, sql):
    s = SqlRequest()
    s.transaction_ref = t
    s.sql = sql['sql']
    s.status = sql['status']
    s.description = sql['description']
    s.owner = sql['owner']
    s.put()

def update_status(o, status):
    o.status = status
    o.put()

    
